You can use the fs.stat() method to get information about a file or directory, including whether it's a file or directory. Here's an example:
fs.stat()